#include "widget.h"
#include "desktopwidget.h"
#include "hardinterfacetest/hardinterfacetest.h"
#include "sidebarwidget.h"
#include "settingswidget.h"
#include "gameswidget.h"
#include "userwidget.h"
#include "about/about.h"
#include "weiqiantools/weiqiantools.h"
#include "netsetting/netsettings.h"
#include "cputemp/cputemp.h"
#include "wifi/wifi.h"
#include "touchcalibration/ts.h"
#include "hardinterfacetest/hardinterfacetest.h"
#include "weiqiantools/weiqianfunctions.h"
#include "web/web.h"
#include "timesettings/timesettings.h"
#include "picture/picture.h"
#include "configargs.h"
#include "paintbasic/paintarea.h"
#include "music/music.h"
#include "file/file.h"
#include "jwidget/jdialog.h"
#include <QFile>
#include <QFrame>
#include <QLabel>
#include <QMouseEvent>
#include <QPushButton>
#include <QTimer>
#include <unistd.h>
#include "sidebarwidget.h"
#include <QWSServer>
#include <QPainter>
#include <QRect>
#include <QDir>
#include <performance/performanceWidget.h>
#include <version/versionInfo.h>
#include <RNDIS/rndis.h>

int havecal=1;

//Paincor::Widget(QWidget *parent)
//    : QWidget(parent)
//{
//    ;
// //   xx=yy=0;
//  //  resize(200,200);
//}

//void Paincor::mousePressEvent(QMouseEvent *event)
//{
//     xx=event->pos().x();
//     yy=event->pos().y();
//     update();
//     qDebug("xx=%d,yy=%d",xx,yy);
//}

//void Paincor::paintEvent(QPaintEvent *event)
//{
//    QPainter painter(this);                               //创建一个画笔
//    QPen pen;
//    pen.setColor(Qt::red);
//        pen.setWidth(5);
//     painter.setPen(pen);
//     painter.drawPoint(xx,yy);
//}

tmpQDialog::tmpQDialog(QWidget *parent):QDialog(parent)
{
//    QDialog * setdialog = new QDialog;
    settmp = new QLabel;
    havecal=1;
    QPushButton *tmpbut = new QPushButton;
    tmpbut->setText(tr("开始校准"));
    tmpbut->setMinimumSize(200,100);
    QPushButton *tmpbut1 = new QPushButton;
    tmpbut1->setText(tr("关闭"));
    tmpbut1->setMinimumSize(200,100);
    settmp->setText(tr("请从左上角依次点击屏幕上出现的5个光标！"));
    settmp->setStyleSheet("color:red;");
    connect(tmpbut1,SIGNAL(clicked()),this,SLOT(tmpclose()));
    connect(tmpbut,SIGNAL(clicked()),this,SLOT(close()));
    QGridLayout *tmplayout = new QGridLayout;
    tmplayout->setSpacing(20);
    tmplayout->addWidget(settmp,0,0,1,1);
    tmplayout->addWidget(tmpbut,1,0,1,1);
    tmplayout->addWidget(tmpbut1,2,0,1,1);
    if (DebugOrRelease)
    this->setCursor(Qt::CrossCursor);
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setLayout(tmplayout);
    this->exec();
}
void tmpQDialog::tmpclose()
{
    havecal=0;
    this->close();
}

tmpQDialog::~tmpQDialog()
{
   // ;
}


void readLcdInfo()
{
	qDebug("widget.cpp readlcdinfo 103");

    QFile filecmd("/proc/cmdline");
    filecmd.open(QIODevice::ReadOnly);
    
    QString cmdline(filecmd.readAll());
  	
  	QStringList tmp = cmdline.split(' ', QString::SkipEmptyParts);


	for(int i=0; i<tmp.length(); i++)
	{
//		qDebug() << tmp[i];
		if(tmp[i].contains("lcdsize"))
		{
			tmp[i].replace("lcdsize=", "");
			QStringList tmp1 = tmp[i].split('x', QString::SkipEmptyParts);
//			qDebug() << tmp1;

			int_WIDGET_W = tmp1[0].toInt();
			int_WIDGET_H = tmp1[1].toInt();
			break;
		}
	}

	g_lcdsize.clear();
    if(int_WIDGET_W==1280 && int_WIDGET_H==800)
    {
        qDebug("use %s", LCDSIZE_1280x800);
        g_lcdsize = LCDSIZE_1280x800;

    }

	if(int_WIDGET_W==1024 && int_WIDGET_H==768)
	{
		qDebug("use %s", LCDSIZE_1024x768);
		g_lcdsize = LCDSIZE_1024x768;

	}
	
	if(int_WIDGET_W==800 && int_WIDGET_H==600)
	{
		qDebug("use %s", LCDSIZE_800x600);
		g_lcdsize = LCDSIZE_800x600;

	}

	
	if(int_WIDGET_W==800 && int_WIDGET_H==480)
	{
		qDebug("use %s", LCDSIZE_800x480);
		g_lcdsize = LCDSIZE_800x480;

	}

	
	if(int_WIDGET_W==480 && int_WIDGET_H==272)
	{
		qDebug("use %s", LCDSIZE_480x272);
		g_lcdsize = LCDSIZE_480x272;
	}

	qDebug("wide=%d high=%d", int_WIDGET_W, int_WIDGET_H);

}

void setLcdInfo()
{
    readLcdInfo();
    QFile f;

	
    if(g_lcdsize == LCDSIZE_1024x768 || g_lcdsize == LCDSIZE_1280x800)
    {
    	
		qDebug("use LCDSIZE_1024x768");
#if 1
		TOPMARGIN	  =  75;	//桌面整体为止相关参数
		BOTTOMMARGIN   = 75;
		LEFTMARGIN	   = 60;
		RIGHTMARGIN   =  60;
#endif			

		SUBLEFTMARGIN	 =	40; 		  
		SUBRIGHTMARGIN	 =	40;
		SUBTOPMARGIN 	 =	25;
		SUBBOTTOMMARGIN	 =	25;
		SUBSPACE 	  =  20;			   //桌面控件之间的间距

		SIDEBAR_H 	=  int_WIDGET_H;
		SIDEBAR_W 	=  100;

		SUBWIDGET_H	=  (int_WIDGET_H - TOPMARGIN - BOTTOMMARGIN);	//桌面的高度
		SUBWIDGET_W	=  (int_WIDGET_W - LEFTMARGIN - RIGHTMARGIN - SIDEBAR_W); //桌面的宽度
		SUBWIDGET_X	=  (SIDEBAR_W + LEFTMARGIN);  //桌面的起始坐标x
		SUBWIDGET_Y	=  TOPMARGIN;				//桌面的起始坐标y

		USERWIDGET_MARGIN    =   20;
		USERWIDGET_BLUEFRAME_W	=  (400 - USERWIDGET_MARGIN); //用户登录界面那块蓝色区域的宽度
		USERWIDGET_BLUEFRAME_H	=  (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
		USERWIDGET_WHITEFRAME_W	=  (SUBWIDGET_W - USERWIDGET_MARGIN - USERWIDGET_MARGIN - USERWIDGET_BLUEFRAME_W);//用户登录界面那块白色区域的宽度
		USERWIDGET_WHITEFRAME_H	 = (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
		f.setFileName(":/text/about/about7b.txt");

    }else   if(g_lcdsize == LCDSIZE_800x600)
    {
		qDebug("use LCDSIZE_800x600");
		qDebug(" This pad is 7 cun biao qing");//使用这个配置

#if 1
		TOPMARGIN     =  60;    //桌面整体为止相关参数
		BOTTOMMARGIN   = 60;
		LEFTMARGIN     = 35;
		RIGHTMARGIN   =  55;
#endif			

		SUBLEFTMARGIN     =  40;           
		SUBRIGHTMARGIN    =  40;
		SUBTOPMARGIN      =  25;
		SUBBOTTOMMARGIN   =  25;
		SUBSPACE       =  15;               //桌面控件之间的间距

		SIDEBAR_H     =  int_WIDGET_H;
		SIDEBAR_W     =  100;

		SUBWIDGET_H   =  (int_WIDGET_H - TOPMARGIN - BOTTOMMARGIN);   //桌面的高度
		SUBWIDGET_W   =  (int_WIDGET_W - LEFTMARGIN - RIGHTMARGIN - SIDEBAR_W); //桌面的宽度
		SUBWIDGET_X   =  (SIDEBAR_W + LEFTMARGIN);  //桌面的起始坐标x
		SUBWIDGET_Y   =  TOPMARGIN;				//桌面的起始坐标y

		USERWIDGET_MARGIN    =   20;
		USERWIDGET_BLUEFRAME_W    =  (400 - USERWIDGET_MARGIN); //用户登录界面那块蓝色区域的宽度
		USERWIDGET_BLUEFRAME_H    =  (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
		USERWIDGET_WHITEFRAME_W   =  (SUBWIDGET_W - USERWIDGET_MARGIN - USERWIDGET_MARGIN - USERWIDGET_BLUEFRAME_W);//用户登录界面那块白色区域的宽度
		USERWIDGET_WHITEFRAME_H    = (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
          f.setFileName(":/text/about/about7b.txt");
    } else  if(g_lcdsize == LCDSIZE_800x480)
    {
          qDebug("LCDSIZE_800x480");//使用这个配置
        
#if 1
          TOPMARGIN     =  40;    //桌面整体为止相关参数
          BOTTOMMARGIN   = 40;
         LEFTMARGIN     = 35;
			RIGHTMARGIN   =  55;
#endif			

           SUBLEFTMARGIN     =  40;           
           SUBRIGHTMARGIN    =  40;
		   SUBTOPMARGIN      =  25;
           SUBBOTTOMMARGIN   =  25;
           SUBSPACE       =  15;               //桌面控件之间的间距

          SIDEBAR_H     =  int_WIDGET_H;
          SIDEBAR_W     =  100;

          SUBWIDGET_H   =  (int_WIDGET_H - TOPMARGIN - BOTTOMMARGIN);   //桌面的高度
          SUBWIDGET_W   =  (int_WIDGET_W - LEFTMARGIN - RIGHTMARGIN - SIDEBAR_W); //桌面的宽度
          SUBWIDGET_X   =  (SIDEBAR_W + LEFTMARGIN);  //桌面的起始坐标x
          SUBWIDGET_Y   =  TOPMARGIN;				//桌面的起始坐标y

          USERWIDGET_MARGIN    =   20;
          USERWIDGET_BLUEFRAME_W    =  (400 - USERWIDGET_MARGIN); //用户登录界面那块蓝色区域的宽度
          USERWIDGET_BLUEFRAME_H    =  (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
          USERWIDGET_WHITEFRAME_W   =  (SUBWIDGET_W - USERWIDGET_MARGIN - USERWIDGET_MARGIN - USERWIDGET_BLUEFRAME_W);//用户登录界面那块白色区域的宽度
          USERWIDGET_WHITEFRAME_H    = (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
          f.setFileName(":/text/about/about7b.txt");
		  
    }else if(g_lcdsize == LCDSIZE_480x272){
    	qDebug(" This pad is 4.3 inch");//使用这个配置

		TOPMARGIN 			=	20;	  	//桌面按键距离顶部距离(像素)
		BOTTOMMARGIN	 	= 	20;		//桌面按键距离底部距离(像素)
		LEFTMARGIN 			= 	30;		//同上左边
		RIGHTMARGIN   		=  	30;		//你懂的

		SUBLEFTMARGIN	 =	20; 	//继承jdialog的类的窗口距离屏幕边界的距离	  
		SUBRIGHTMARGIN	 =	20;
		SUBTOPMARGIN 	 =	12;
		SUBBOTTOMMARGIN	 =	12;
		SUBSPACE 	  	 =  8;			   //桌面控件之间的间距

		SIDEBAR_H 	=  int_WIDGET_H;
		SIDEBAR_W 	=  50;				//最左边那一竖排按键的宽

		SUBWIDGET_H	=  (int_WIDGET_H - TOPMARGIN - BOTTOMMARGIN);	//桌面的高度
		SUBWIDGET_W	=  (int_WIDGET_W - LEFTMARGIN - RIGHTMARGIN - SIDEBAR_W); //桌面的宽度
		SUBWIDGET_X	=  (SIDEBAR_W + LEFTMARGIN);  //桌面的起始坐标x
		SUBWIDGET_Y	=  TOPMARGIN;				//桌面的起始坐标y

		USERWIDGET_MARGIN    =   20;
		USERWIDGET_BLUEFRAME_W	=  (160 - USERWIDGET_MARGIN); //用户登录界面那块蓝色区域的宽度
		USERWIDGET_BLUEFRAME_H	=  (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
		USERWIDGET_WHITEFRAME_W	=  (SUBWIDGET_W - USERWIDGET_MARGIN - USERWIDGET_MARGIN - USERWIDGET_BLUEFRAME_W);//用户登录界面那块白色区域的宽度
		USERWIDGET_WHITEFRAME_H	 = (SUBWIDGET_H - USERWIDGET_MARGIN - USERWIDGET_MARGIN);//同上的高度
		f.setFileName(":/text/about/about7b.txt");

    }


    f.open(QFile::ReadOnly);

    
    while(!f.atEnd()) {
        if(g_lcdsize == LCDSIZE_1024x768 || g_lcdsize == LCDSIZE_1280x800)
        	retmp.append("<p style = 'line-height:200%; text-indent:45px;'>"); //桌面图标缩放的
        else if(g_lcdsize == LCDSIZE_800x600)
       	 	retmp.append("<p style = 'line-height:150%; text-indent:25px;'>");
        else if(g_lcdsize == LCDSIZE_800x480)
        	retmp.append("<p style = 'line-height:200%; text-indent:25px;'>");
		else if(g_lcdsize == LCDSIZE_480x272)
			retmp.append("<p style = 'line-height:100%; text-indent:10px;'>"); //桌面图标缩放的

        retmp.append(f.readLine());
        retmp.append("</p>");
    }
}

Widget::Widget(QWidget *parent) : QWidget(parent)
{
    flags_dianzu=0;
    xx=0;
    yy=0;

    
    setLcdInfo();
    m_pLockTip = new QLabel;
    m_pLockTip->setText("asfasdf");

    
    m_CalFlag=0;
    m_CalNo =0;
    
    checkmouse1.timecheckmouxe();
    checkmouse1.start();
	
    QFrame *pFrame = new QFrame(this);
    pFrame->setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    pFrame->setObjectName("myFrame");

    this->resize(int_WIDGET_W, int_WIDGET_H);
    this->setWindowFlags(Qt::FramelessWindowHint);
    m_pSidebarWidget = new SidebarWidget(pFrame);
    m_pSidebarWidget->setGeometry(0, 0, SIDEBAR_W, SIDEBAR_H);

    m_pDesktopWidget = new DesktopWidget(pFrame);
    m_pDesktopWidget->setGeometry(SUBWIDGET_X, SUBWIDGET_Y, SUBWIDGET_W, SUBWIDGET_H);//半透明桌面的大小

    m_pSettingsWidget = new SettingsWidget(pFrame);		
    m_pSettingsWidget->setGeometry(SUBWIDGET_X, SUBWIDGET_Y, SUBWIDGET_W, SUBWIDGET_H);  
	m_pSettingsWidget->setVisible(false);
	qDebug("SUBWIDGET_X=%d, SUBWIDGET_Y=%d, SUBWIDGET_W=%d, SUBWIDGET_H=%d", SUBWIDGET_X, SUBWIDGET_Y, SUBWIDGET_W, SUBWIDGET_H);
	
	
    m_pGameWidget = new GamesWidget(pFrame);
    m_pGameWidget->setGeometry(SUBWIDGET_X, SUBWIDGET_Y, SUBWIDGET_W, SUBWIDGET_H);
    m_pGameWidget->setVisible(false);
	

    m_pUserWidget = new UserWidget(pFrame);
    m_pUserWidget->setGeometry(SUBWIDGET_X, SUBWIDGET_Y, SUBWIDGET_W, SUBWIDGET_H);
    m_pUserWidget->setVisible(false);

    loadQss(); //读取背景图片
	

    m_pSmokeBtn = new QPushButton(pFrame);  //黑屏选项
    m_pSmokeBtn->resize(pFrame->size());
    m_pSmokeBtn->setVisible(false);

    this->setMouseTracking(true);
	

    connect(m_pSidebarWidget, SIGNAL(userBtnChecked()), this, SLOT(slotShowUserWidget()));
    connect(m_pSidebarWidget, SIGNAL(desktopBtnChecked()), this, SLOT(slotShowDesktopWidget()));
    connect(m_pSidebarWidget, SIGNAL(gamesBtnChecked()), this, SLOT(slotShowGameWidget()));
    connect(m_pSidebarWidget, SIGNAL(settingBtnChecked()), this, SLOT(slotShowSettingsWidget()));
    connect(m_pSidebarWidget, SIGNAL(lockBtnClicked()), this, SLOT(slotLock()));

    connect(m_pDesktopWidget, SIGNAL(wqTestBtnClicked()), this, SLOT(slotShowWeiqianToolsWidget()));
   // connect(mp_wqceshi, SIGNAL(wqceshiTestBtnClicked()), this, SLOT(slotShowWeiqianToolsWidget()));
    connect(m_pDesktopWidget, SIGNAL(aboutBtnClicked()), this, SLOT(slotShowAboutWidget()));
    connect(m_pDesktopWidget, SIGNAL(webBtnClicked()), this, SLOT(slotShowWebWidget()));
    connect(m_pDesktopWidget, SIGNAL(timeBtnClicked()), this, SLOT(slotShowTimeWidget()));
    connect(m_pDesktopWidget, SIGNAL(photoBtnClicked()), this, SLOT(slotShowPhotoWidget()));
    connect(m_pDesktopWidget, SIGNAL(musicBtnClicked()), this, SLOT(slotShowMusicWidget()));
    connect(m_pDesktopWidget, SIGNAL(folderBtnClicked()), this, SLOT(slotShowFolderWidget()));

    connect(m_pSettingsWidget, SIGNAL(netWorkingBtnClicked()), this, SLOT(slotShowNetSettingsWidget()));
    connect(m_pSettingsWidget, SIGNAL(ceshiWorkingBtnClicked()), this, SLOT(slotShowCeshiSettingsWidget()));
    connect(m_pSettingsWidget, SIGNAL(wifiWorkingBtnClicked()), this, SLOT(slotShowWifiSettingsWidget()));
    connect(m_pSettingsWidget, SIGNAL(touchCalBtnClicked()), this, SLOT(slotShowTouchSettingsWidget()));
    connect(m_pSettingsWidget, SIGNAL(cpuTempBtnClicked()), this, SLOT(slotShowCpuTempSettingsWidget()));
    connect(m_pGameWidget, SIGNAL(painBtnClicked()), this, SLOT(slotShowGamePainWidget()));
    connect(m_pSmokeBtn, SIGNAL(clicked(bool)), this, SLOT(slotHideSmokeBtn()));
	connect(m_pSettingsWidget, SIGNAL(performanceBtnClicked()), this, SLOT(slotShowPerformanceWidget()));
    connect(m_pSettingsWidget, SIGNAL(versionInfoBtnClicked()), this, SLOT(slotShowVersionInfoWidget()));
    connect(m_pSettingsWidget, SIGNAL(RNDISBtnClicked()), this, SLOT(slotShowRNDISWidget()));
    m_isLock = false;
}

Widget::~Widget()
{

}

void Widget::slotShowUserWidget()
{   if(!m_CalNo) {
    widgetHidden();
    if(!m_pUserWidget->isVisible()) {
        m_pUserWidget->setVisible(true);
    }
    }
    if(m_CalNo)
        m_CalNo=0;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
//     xx=event->pos().x();
//     yy=event->pos().y();
//     update();
  //   Paincor painttmp = new Paincor();

  //   qDebug("xx=%d,yy=%d",xx,yy);

}

void Widget::mouseReleaseEvent(QMouseEvent *e){

}

void Widget::mouseMoveEvent(QMouseEvent *event)
{

}

void Widget::paintEvent(QPaintEvent *event)
{
//        QPainter painter(this);
//        painter.drawLine(0,0,100,100);
//        QPen pen(Qt::green,5,Qt::DashDotDotLine,Qt::FlatCap,Qt::RoundJoin);                                 //创建一个画笔

//         painter.setPen(pen);
//         QRect rectangle(70.0,40.0,80.0,60.0);
//         int starAngle=30*16;
//         int spanAngle=120*16;
//         painter.drawArc(rectangle,starAngle,spanAngle);
//         pen.setWidth(2);
//         pen.setStyle(Qt::SolidLine);
//         painter.setPen(pen);
//         painter.drawRect(50,50,20,100);
//        qDebug("paintevent  66666666");
}

void Widget::slotShowDesktopWidget()
{
    widgetHidden();
    if(!m_pDesktopWidget->isVisible()) {
        m_pDesktopWidget->setVisible(true);
    }
}

void Widget::slotShowSettingsWidget()
{
    widgetHidden();
    if(!m_pSettingsWidget->isVisible()) {
        m_pSettingsWidget->setVisible(true);
    }
}
void Widget::slotShowGameWidget()
{
    widgetHidden();
    if(!m_pGameWidget->isVisible()) {
        m_pGameWidget->setVisible(true);
    }
}

void Widget::slotLock()
{  if(!m_CalNo)
    if(!m_isLock) {
//		system("echo 0 > /sys/class/backlight/backlight/brightness");
        WeiqianFunctions::SetBackLight(0);
        system("wq_pwm_app.elf /dev/wq_pwm w 1");
        system("wq_pwm_app.elf /dev/wq_pwm w 0");
        if(!m_pSmokeBtn->isVisible()) {
            m_pSmokeBtn->setVisible(true);
        }
        m_isLock = true;
    }
    if(m_CalNo)
        m_CalNo=0;
}

void Widget::slotShowWeiqianToolsWidget()
{
    WeiqianTools wqTools;
    wqTools.setStyleSheet(this->readSubQss());
    wqTools.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    wqTools.exec();
}

void Widget::slotShowNetSettingsWidget()
{
    NetSettings netSettings;
    netSettings.setStyleSheet(this->readSubQss());
    netSettings.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    netSettings.exec();
}
void Widget::slotShowWifiSettingsWidget()
{
    WifiSeting wifiSettings;
    wifiSettings.setStyleSheet(this->readSubQss());
    wifiSettings.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    wifiSettings.exec();
}

void Widget::slotShowCeshiSettingsWidget()
{
    CeshiSettings ceshiSettings;
    ceshiSettings.setStyleSheet(this->readSubQss());
    ceshiSettings.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    ceshiSettings.exec();
}

void Widget::slotShowCpuTempSettingsWidget()
{
    CpuTemp cputemp;
    cputemp.setStyleSheet(this->readSubQss());
    cputemp.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    cputemp.exec();
}

#if 0
void Widget::slotShowTouchSettingsWidget()
{
  //  ping -c 10 192.168.1.16 | grep loss
 /*    QString command ="ping";
     QString command_full = command;
     char *S;
     command_full.append(filePath);
     command_full.append(fileName);
     command_full.append(backend);
     S = (command_full.toAscii()).data();
     system(S);

*/

//}
 //   qDebug("toucr");
system("mv /etc/pointercal /etc/pointercalbk");
system("sync");
system("mv /etc/pointercalbk /etc/pointercal");
system("sync");
    tmpQDialog tmmp;
    tmmp.show();
    usleep(1000);
   if(havecal){
       qDebug("havecal");
    m_CalNo =1;
    if(m_CalFlag<2)
    m_CalFlag++;
    if(m_CalFlag==2)
        m_CalFlag=0;
   
    this->setCursor(Qt::BlankCursor);

    system("/usr/local/tslib/bin/ts_calibrate");
 
    this->setCursor(Qt::ArrowCursor);
    update();
   }else {
       ;
   }
   system("sync");
}
#endif

void Widget::slotShowTouchSettingsWidget()
{

	tsClass tool;

	tool.setStyleSheet(this->readSubQss());

	tool.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
	tool.exec();
}
void Widget::slotShowGamePainWidget()
{
   PaintArea painTools;
  painTools.setStyleSheet(this->readSubQss());
    painTools.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    painTools.exec();
}

void Widget::slotShowAboutWidget()
{
    About about;
    about.setStyleSheet(this->readSubQss());
    about.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    about.exec();
}

void Widget::slotShowWebWidget()
{
    Web web;
    web.setStyleSheet(this->readSubQss());
    web.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    web.exec();
}

void Widget::slotShowTimeWidget()
{
    TimeSettings timeSettings;
    timeSettings.setStyleSheet(this->readSubQss());
    timeSettings.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    timeSettings.exec();
}

void Widget::slotShowPhotoWidget()
{
    PictureWidget pictureWidget;
    pictureWidget.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    pictureWidget.exec();
}


void Widget::slotShowMusicWidget()
{
	if(g_lcdsize == LCDSIZE_480x272)
	{
		QMessageBox::information(NULL, tr("提示"), QString("本产品没有音频"));
	}else{
	    Music musicWidget;
	    musicWidget.setStyleSheet(this->readSubQss());
	    musicWidget.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
	    musicWidget.exec();
    }
}

void Widget::slotShowFolderWidget()
{
    Folder folderTools;
    folderTools.setStyleSheet(this->readSubQss());
    folderTools.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    folderTools.exec();
}

void Widget::slotHideSmokeBtn()
{
    if(m_isLock) {
        if(m_pSmokeBtn->isVisible()) {
			qDebug("is Visible!");
            m_pSmokeBtn->setVisible(false);
        }
        QTimer::singleShot(50, this, SLOT(slotTimerOpenBacklight()));
        m_isLock = false;
    }
}

void Widget::slotTimerOpenBacklight()
{
    WeiqianFunctions::SetBackLight(1);
    system("wq_pwm_app.elf /dev/wq_pwm w 128");
	qDebug("call slotTimerOpenBacklight!");


//	system("echo 1 > /sys/class/backlight/backlight/brightness");

}

void Widget::slotShowPerformanceWidget()
{
	Performance performance;
	
	performance.setStyleSheet(this->readSubQss());

	performance.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
	performance.exec();


}

void Widget::slotShowVersionInfoWidget()
{
    versionClass version;

    version.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    version.exec();
    qDebug("version info show\n");
}

void Widget::slotShowRNDISWidget()
{
    rndis rndisDialog;
    rndisDialog.setGeometry(0, 0, int_WIDGET_W, int_WIDGET_H);
    rndisDialog.exec();
    qDebug("RNDIS show\n");
}


void Widget::loadQss()
{
    QFile qss;

    if(g_lcdsize == LCDSIZE_1280x800){
        qss.setFileName(":/qss/linuxdesktop/stylesheet/mainwindow_1280x800.qss");
    }else if(g_lcdsize == LCDSIZE_1024x768){
        qss.setFileName(":/qss/linuxdesktop/stylesheet/mainwindow_1024x768.qss");
    }else if(g_lcdsize == LCDSIZE_800x600){
        qss.setFileName(":/qss/linuxdesktop/stylesheet/mainwindow_800x600.qss");
    }else if(g_lcdsize == LCDSIZE_800x480){   
        qss.setFileName(":/qss/linuxdesktop/stylesheet/mainwindow_800x480.qss");//读取背景图片
    }else if(g_lcdsize == LCDSIZE_480x272){   
        qss.setFileName(":/qss/linuxdesktop/stylesheet/mainwindow_480x272.qss");//读取背景图片
    }
		 

    qss.open(QFile::ReadOnly);
    QString qssStr = qss.readAll(); 
	
    this->setStyleSheet(qssStr);
}

void Widget::widgetHidden()
{
    if(m_pDesktopWidget->isVisible()) {
        m_pDesktopWidget->setVisible(false);
    }
    if(m_pSettingsWidget->isVisible()) {
        m_pSettingsWidget->setVisible(false);
    }
    if(m_pUserWidget->isVisible()) {
        m_pUserWidget->setVisible(false);
    }
    if(m_pGameWidget->isVisible()) {
        m_pGameWidget->setVisible(false);
    }
}

QString Widget::readSubQss()
{
    QString iconQssStr;
    QString sizeQssStr;
    if(g_lcdsize == LCDSIZE_1024x768 || g_lcdsize == LCDSIZE_1280x800){
        QFile sizeQss(":/qss/linuxdesktop/stylesheet/subwidgetsize_1024x768.qss");
        QFile iconQss(":/qss/linuxdesktop/stylesheet/subwidgeticon_1024x768.qss");
        sizeQss.open(QFile::ReadOnly);
        sizeQssStr = sizeQss.readAll();

        iconQss.open(QFile::ReadOnly);
        iconQssStr = iconQss.readAll();
    }else if(g_lcdsize == LCDSIZE_800x600){
		QFile sizeQss(":/qss/linuxdesktop/stylesheet/subwidgetsize_800x600.qss");
		sizeQss.open(QFile::ReadOnly);
		sizeQssStr = sizeQss.readAll();

		QFile iconQss(":/qss/linuxdesktop/stylesheet/subwidgeticon_800x600.qss");
		iconQss.open(QFile::ReadOnly);
		iconQssStr = iconQss.readAll();
    }else   if(g_lcdsize == LCDSIZE_800x480){
		QFile sizeQss(":/qss/linuxdesktop/stylesheet/subwidgetsize7b.qss");
		sizeQss.open(QFile::ReadOnly);
		sizeQssStr = sizeQss.readAll();
		QFile iconQss(":/qss/linuxdesktop/stylesheet/subwidgeticon7b.qss");
		iconQss.open(QFile::ReadOnly);
		iconQssStr = iconQss.readAll();
    }else   if(g_lcdsize == LCDSIZE_480x272){
		QFile sizeQss(":/qss/linuxdesktop/stylesheet/subwidgetsize_480x272.qss");
		sizeQss.open(QFile::ReadOnly);
		sizeQssStr = sizeQss.readAll();
		QFile iconQss(":/qss/linuxdesktop/stylesheet/subwidgeticon_480x272.qss");
		iconQss.open(QFile::ReadOnly);
		iconQssStr = iconQss.readAll();
    }

    return (sizeQssStr + iconQssStr);
}

QString Widget::readQssFromName(QString fileName)
{
    QString path = ":/qss/linuxdesktop/stylesheet/";
    path.append(fileName);
    QFile iconQss(path);
    iconQss.open(QFile::ReadOnly);
    return iconQss.readAll();
}
